//
//  UseCarView.swift
//  PageChange
//
//  Created by Pro on 2018/3/29.
//  Copyright © 2018年 Pro. All rights reserved.
//

import UIKit

class UseCarView: UIView {

        var ConnectView:UIView!
        
        var ButtonCallBack:((_ type : Int) -> ())?
    
        var pageValue:Int = 0 {
        didSet {
            
        }
    }
    
    
    
    
    @IBOutlet weak var countPriceBtn: UIButton!
    
    
        @IBAction func UseCarOrUserProtical(_ sender: UIButton) {
            
            if sender == countPriceBtn && ButtonCallBack != nil {
                ButtonCallBack!(1)
            }
           
        }
        
        override init(frame: CGRect) {
            super.init(frame: frame)
            ConnectView = loadViewFromNib()
            addSubview(ConnectView)
            addConstraints()
            initialSetup()
        }
        
        
        
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            ConnectView = loadViewFromNib()
            addSubview(ConnectView)
            addConstraints()
            initialSetup()
        }
        
        func loadViewFromNib() -> UIView {
            let className = type(of: self)
            let bundle = Bundle(for: className)
            let name = NSStringFromClass(className).components(separatedBy: ".").last
            let nib = UINib(nibName: name!, bundle: bundle)
            let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
            return view
        }
        
        func addConstraints() {
            ConnectView.translatesAutoresizingMaskIntoConstraints = false
            var constraint = NSLayoutConstraint(item: ConnectView, attribute: .leading,
                                                relatedBy: .equal, toItem: self, attribute: .leading,
                                                multiplier: 1, constant: 0)
            addConstraint(constraint)
            constraint = NSLayoutConstraint(item: ConnectView, attribute: .trailing,
                                            relatedBy: .equal, toItem: self, attribute: .trailing,
                                            multiplier: 1, constant: 0)
            addConstraint(constraint)
            constraint = NSLayoutConstraint(item: ConnectView, attribute: .top, relatedBy: .equal,
                                            toItem: self, attribute: .top, multiplier: 1, constant: 0)
            addConstraint(constraint)
            constraint = NSLayoutConstraint(item: ConnectView, attribute: .bottom,
                                            relatedBy: .equal, toItem: self, attribute: .bottom,
                                            multiplier: 1, constant: 0)
            addConstraint(constraint)
        }
        
        //初始化默认属性配置
        func initialSetup(){
//            self.backgroundColor = UIColor(red: 0/225.0, green: 0/225.0, blue: 0/225.0, alpha: 0.3)
              self.backgroundColor = UIColor.clear
        }
        
    }

